﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_FAQ_ctrFAQCategory : System.Web.UI.UserControl
{
    private int nCurrentLanguage = Support.GetCurrentLanguage();
    private int nDefaultLanguage = Support.GetDefaultLanguage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.InitData(1);
        }
    }
    private void initDataPaging()
    {
    }
    private void InitData(int CurrentPageIndex)
    {
        DataTable dtbFAQs = new DataTable();
        FAQCategory objFAQCat = new FAQCategory();
        dtbFAQs = objFAQCat.Search();
        rptNameCat.DataSource = dtbFAQs;
        rptNameCat.DataBind();
    }

    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        Pager.CurrentIndex = currnetPageIndx;
        this.InitData(currnetPageIndx);
    }

    private void VisiblePaging(int intPagecount)
    {
        int nPageSize = 0;
        nPageSize = 22;
        if (intPagecount > nPageSize)
            Pager.Visible = true;
        else
            Pager.Visible = false;
    }
    
    protected void dtlFAQByCat_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkQuestion = (HyperLink)e.Item.FindControl("lnkQuestion");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "FAQID"));
            int nCurrentLanguage = Support.GetCurrentLanguage();
            int nDefaultLanguage = Support.GetDefaultLanguage();

            lnkQuestion.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Question"));
            lnkQuestion.NavigateUrl = Config.ROOT + Pages.FrontEnds.FAQ + "?" + Config.FAQ_ID + "=" + nID;

            HyperLink lnkReadMore = (HyperLink)e.Item.FindControl("lnkReadMore");
            lnkReadMore.NavigateUrl = Config.ROOT + Pages.FrontEnds.FAQ + "?" + Config.FAQ_ID + "=" + nID;
            lnkReadMore.Text = MultipleLanguage.LINK_READMORE[nCurrentLanguage - 1];
        }
    }
    protected void rptNameCat_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Repeater rptFAQByCat = (Repeater)e.Item.FindControl("rptFAQByCat");
            Literal ltrTabContent = (Literal)e.Item.FindControl("ltrTabContent");
            int nPageSize = 20;
            int nPageCount = 0;
            ltrTabContent.Text = "<div class=\"tab-content\" id=\"divTabContent" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "FAQCategoryID")) + "\" >";
            try
            {
                DataTable dtb = new DataTable();
                FAQs objFAQ = new FAQs();
                dtb = objFAQ.Search(0, 0, "", ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "FAQCategoryID")), nDefaultLanguage, nCurrentLanguage, EnumeType.ACTIVE, 1, nPageSize, ref nPageCount);
                rptFAQByCat.DataSource = dtb;
                rptFAQByCat.DataBind();

                Pager.Visible = true;
                VisiblePaging(nPageCount);
                Pager.ItemCount = nPageCount;
            }
            catch
            {
                Response.Redirect("~/Default.aspx");
            }
        }
    }
}